package com.hyy.springbootblog.common.pojo;

import com.hyy.springbootblog.common.enums.ResultStatus;
import lombok.Data;

@Data
public class Result<T>{
    private int code;
    private String errMsg;
    private T data;
    public static <T> Result<T> ok(T data){
        Result<T> result = new Result<T>();
        result.setCode(ResultStatus.SUCCESS.getCode());
        result.setData(data);
        result.setErrMsg("");
        return result;
    }



    public static <T> Result<T> fail(String errMsg){
        Result<T> result = new Result<T>();
        result.setCode(ResultStatus.FAIL.getCode());
        result.setData(null);
        result.setErrMsg(errMsg);
        return result;
    }

    public static <T> Result<T> fail(String errMsg,T data){
        Result<T> result = new Result<T>();
        result.setCode(ResultStatus.FAIL.getCode());
        result.setData(data);
        result.setErrMsg(errMsg);
        return result;
    }

}
